package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜品管理
 */
@Api(value = "/admin/dish", tags = {"菜品管理"})
@RestController
@RequestMapping("/admin/dish")
public class DishController {
    @Autowired
    private DishService dishService;

    /**
     * 新增菜品和该菜品对应的口味
     * @param dishDTO
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "DishDTO", name = "dishDTO", value = "", required = true)
    })
    @ApiOperation(value = "新增菜品和该菜品对应的口味", notes = "新增菜品和该菜品对应的口味", httpMethod = "POST")
    @PostMapping
    public Result save(@RequestBody DishDTO dishDTO) {
        return dishService.insertDishWithFlavor(dishDTO);
    }

    /**
     * 分页查询菜品信息
     * @param dishPageQueryDTO
     * @return
     */
    @ApiOperation(value = "分页查询菜品信息", notes = "分页查询菜品信息", httpMethod = "GET")
    @GetMapping("/page")
    public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO) {
        return dishService.dishPageQuery(dishPageQueryDTO);
    }
    /**
     * 批量删除功能
     */
    @ApiOperation(value = "批量删除功能", notes = "批量删除功能", httpMethod = "DELETE")
    @DeleteMapping
    public Result delete(String ids) {
        return dishService.deleteDish(ids);
    }

    /**
     * 更新菜品起/停售状态
     * @param status
     * @param id
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "status", value = "", required = true)
    })
    @ApiOperation(value = "更新菜品起/停售状态", notes = "更新菜品起/停售状态", httpMethod = "POST")
    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable("status") Integer status, Long id) {
        return dishService.updateStatus(status,id);
    }
    /**
     * 回显菜品信息
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "long", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "回显菜品信息", notes = "回显菜品信息", httpMethod = "GET")
    @GetMapping("/{id}")
    public Result<DishVO> getDish(@PathVariable("id") Long id) {
        return dishService.showDish(id);
    }
    /**
     * 修改菜品信息
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "DishDTO", name = "dishDTO", value = "", required = true)
    })
    @ApiOperation(value = "修改菜品信息", notes = "修改菜品信息", httpMethod = "PUT")
    @PutMapping
    public Result update(@RequestBody DishDTO dishDTO) {
        return dishService.updateDish(dishDTO);
    }

    /**
     * 添加修改套餐时添加回显菜品列表
     * @param categoryId
     * @return
     */
    @ApiOperation(value = "添加修改套餐时添加回显菜品列表", notes = "添加修改套餐时添加回显菜品列表", httpMethod = "GET")
    @GetMapping("/list")
    public Result<List<Dish>> list(Long categoryId) {
        return dishService.dishList(categoryId);
    }
}
